<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>购物车列表</title>
</head>
<body>
<div id="content">
    <h3 class="admin_link_bar">
        <jsp:include page="inc.jsp"/>
    </h3>

    <form method="post" action="addOrders">
        <table style="margin-top:10px;" width="999" align="center" cellpadding="0" cellspacing="0" class="thin-border">
            <tr>
                <td colspan="4">
                    <%--<c:if test="${empty loginUser }">--%>
                    <%--还没有登录<a href="/login/login">去登录</a>--%>
                    <%--</c:if>--%>
                </td>
            </tr>
            <tr>
                <c:if test="${empty shopCart||shopCart.isEmpty }">
                    <td colspan="4">购物车中没有任何商品，请<a href="/user/product/list">选择商品</a></td>
                </c:if>
            </tr>
            <tr>
                <c:if test="${not empty shopCart && not shopCart.isEmpty  }">
                    <td>商品名称</td>
                    <td>商品数量</td>
                    <td>商品总价</td>
                    <td>操作</td>
                </c:if>
            </tr>
            <c:forEach items="${shopCart.products}" var="sc">
                <c:set var="totalPrice" value="${totalPrice+sc.price }"></c:set>
                <tr>
                    <td>${sc.product.name }</td>
                    <td>${sc.number }</td>
                    <td>${sc.price }</td>
                    <td>
                        <a href="/user/order/${sc.product.id }/clearProduct">清除</a>&nbsp;
                        <a href="/user/order/${sc.pid }/addnumber">添加数量</a>
                    </td>
                </tr>
            </c:forEach>


            <c:if test="${not empty addresses && not empty loginUser }">
                <tr>
                    <td colspan="4">选择收货地址</td>
                </tr>
                <tr>
                    <td colspan="4">
                        <a href="/user/address/add">添加收货地址</a>
                    </td>
                </tr>
            </c:if>

            </tr>
            <tr>
                <td colspan="4">
                    <c:forEach items="${addresses}" var="address" varStatus="vs">
                        <c:if test="${vs.index eq 0 }">
                            ${address.name }[${address.phone }]<input type="radio" name="address" checked="checked" value="${address.id }"/><br/>
                        </c:if>
                        <c:if test="${vs.index ne 0 }">
                            ${address.name }[${address.phone }]<input type="radio" name="address" value="${address.id }"/><br/>
                        </c:if>
                    </c:forEach>
                </td>
            </tr>
            <tr>
                <td colspan="4">

                    <c:if test="${not empty shopCart && not shopCart.isEmpty  }">
                        当前商品总价:${totalPrice }
                    </c:if>

                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <c:if test="${not empty shopCart && not shopCart.isEmpty  }">
                        <a href="/user/order/clearShopCart">清空购物车</a>&nbsp;
                    </c:if>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <c:if test="${not empty shopCart && not shopCart.isEmpty && not empty addresses }">
                        [<input type="submit" value="提交订单"/>]
                    </c:if>
                    <input type="hidden" name="totalPrice" value="${totalPrice }"/>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>